{include file="public/meta" /}
<title>{$title | default="标题"}</title>
<meta name="keywords" content="{$keywords|default='关键字'}">
<meta name="description" content="{$desc|default='描述'}">

<body>
    <article class="page-container">
        <form class="form form-horizontal" id="form-admin-add">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <!-- 只有超级管理可以改名字 -->
                    {eq name="$Think.session.user_info_role" value="超级管理员"}
                    <input type="text" class="input-text" value="{$user_info.name}" placeholder="" id="adminName"
                        name="name">
                    {else/}
                    <input type="text" readonly class="input-text" value="{$user_info.name}" placeholder=""
                        id="adminName" name="name">
                    {/eq}
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>新密码：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="password" class="input-text" autocomplete="off" value="{$user_info.pwd}"
                        placeholder="密码" id="password" name="pwd">
                </div>
            </div>
            <!-- 只有超级管理可以改状态 -->
            {eq name="$Think.session.user_info_role" value="超级管理员"}
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>启用状态：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box" style="width: 150px;">
                        <select class="select" name="used" size="1">
                            {if condition="$user_info.used eq 1"}
                            <option value="1" selected>启用</option>
                            <option value="0">禁用</option>
                            {else/}
                            <option value="1">启用</option>
                            <option value="0" selected>禁用</option>
                            {/if}
                        </select>
                    </span>
                </div>
            </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>邮箱：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" placeholder="@" name="email" id="email"
                        value="{$user_info.email}">
                </div>
            </div>
            {/eq}
            <!-- 只有超级管理可以改角色 -->
            {eq name="$Think.session.user_info_role" value="超级管理员"}
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">角色：</label>
                <div class="formControls col-xs-8 col-sm-9"> <span class="select-box" style="width:150px;">
                        <select class="select" name="role" size="1">
                            {if condition="$user_info.role eq '超级管理员'"}
                            <option value="超级管理员" selected>超级管理员</option>
                            <option value="管理员">管理员</option>
                            {else/}
                            <option value="超级管理员">超级管理员</option>
                            <option value="管理员" selected>管理员</option>
                            {/if}
                        </select>
                    </span>
                </div>
            </div>
            {/eq}
            <input type="hidden" name="id" value="{$user_info.id}">
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius disabled" id="submit" type="submit"
                        value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </article>
</body>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/lib/jquery/1.9.1/jquery.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__STATIC__/lib/layer/2.4/layer.js"></script>
<script>
    // 表单验证
    $('form').children().change(function () {
        $("#submit").removeClass('disabled')
    })

    // 表单提交
    $("#submit").on('click', function (event) {
        $.ajax({
            url: "{:url('AdminController/editAdmin')}",
            type: 'post',
            data: $('form').serialize(),
            dataType: 'json',
            success: function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index); // 关闭layer
                    })
                    parent.location.reload(); // 父页面刷新
                } else {
                    layer.msg(res.msg, { icon: 2, time: 1000 })
                }
            }
        })
    })
</script>